// run: $exec < input
#include <iostream>

int d, s1, s2;

int bit_count_one(int x)
{
	x = (x & 0x55555555) + ((x>>1) & 0x55555555);
	x = (x & 0x33333333) + ((x>>2) & 0x33333333);
	x = (x & 0x0F0F0F0F) + ((x>>4) & 0x0F0F0F0F);
	x = (x & 0x00FF00FF) + ((x>>8) & 0x00FF00FF);
	x = (x & 0x0000FFFF) + ((x>>16)& 0x0000FFFF);
	return x;
}

bool judge(int x)
{
	int count = bit_count_one(x);
	return (s1 <= count) && (count <= s2);
}

int main()
{
	int T;
	std::cin >> T;
	for (int ti = 1; ti <= T; ti++) {
		std::cin >> d >> s1 >> s2;
		int ans = d + 1;
		for (; !judge(ans); ans++);
		std::cout << "Case #" << ti << ": " << ans << '\n';
	}

}
